package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author : sunjun
 * @email : sunjun0207@163.com
 * @create 2019/11/11 13:52
 */
/*
移动端
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    //注入setmealService用来操作service
    @Reference
    private SetmealService setmealService;



    /*
    移动端-->根据套餐id查询套餐详细信息,
    (包括套餐基本信息、套餐包含的检查组,检查组包含的检查项)
     */

    @RequestMapping("/findBySetmealId")
    public Result findById(int id){
        //程序健壮性和安全性处理
        try {
            //调用setmealService完成查询
            Setmeal setmeal = setmealService.findBySetmealId(id);
            return new Result(true,MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.GET_SETMEAL_LIST_FAIL);
        }

    }



    /*
    移动端-->获取套餐列表数据
    套餐表
     */
    @RequestMapping("/getAllSetmeal")
    public Result getAllSetmeal(){
        //程序健壮性和安全性处理
        try {
            //调用setmealService完成查询
            List<Setmeal> list = setmealService.findAll();
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.GET_SETMEAL_LIST_FAIL);
        }

    }


}
